//package com.smedi.ismedi.inmail.core.port.adapter.service.impl;
//
//import com.smedi.ismedi.inmail.core.port.adapter.service.WeatherService;
//import com.smedi.ismedi.inmail.core.port.adapter.service.dto.WeatherHistoryResponse;
//import com.smedi.ismedi.inmail.core.port.adapter.service.dto.WeatherNowResponse;
//import lombok.RequiredArgsConstructor;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.web.client.RestTemplateBuilder;
//import org.springframework.http.HttpEntity;
//import org.springframework.http.HttpHeaders;
//import org.springframework.http.HttpMethod;
//import org.springframework.http.ResponseEntity;
//import org.springframework.stereotype.Service;
//import org.springframework.web.client.RestTemplate;
//
//import java.time.LocalDate;
//import java.time.format.DateTimeFormatter;
//import java.util.HashMap;
//import java.util.Map;
//import java.util.Optional;
//
//@RequiredArgsConstructor
//@Service
//public class DingTalkServiceImpl implements DingTalkService {
//    @Value("${ding-talk.url.access-token}")
//    private String accessTokenUrl;
//    @Value("${ding-talk.appKey}")
//    private String appKey;
//    @Value("${ding-talk.appSecret}")
//    private String appSecret;
//
//    private final RestTemplateBuilder restTemplateBuilder;
//
//    @Override
//    public String getAccessToken(String appKey, String appSecret) {
//        RestTemplate restTemplate = restTemplateBuilder.build();
//        HttpMethod method = HttpMethod.POST;
//        return null;
//    }
//
//    @Override
//    public WeatherNowResponse getWeatherNow(Long locationId, String key) {
//        RestTemplate restTemplate = restTemplateBuilder.build();
//        int code = 0;
//        WeatherNowResponse weatherHourly;
//
//        // 发送请求
//        HttpHeaders headers = new HttpHeaders();
//
//        HttpMethod method = HttpMethod.GET;
//
//        Map<String, String> uriVariables = new HashMap<>();
//        uriVariables.put("location", locationId.toString());
//        uriVariables.put("key", qKey);
//
//        HttpEntity<Object> requestEntity = new HttpEntity<>(headers);
//        Optional<ResponseEntity<WeatherNowResponse>> response = Optional.of(restTemplate.exchange(weatherUrlNow, method, requestEntity, WeatherNowResponse.class, uriVariables));
//
//        Optional<Integer> optionalCode = response.map(HttpEntity::getBody).map(WeatherNowResponse::getCode);
//        if (!optionalCode.isPresent()) {
//            return new WeatherNowResponse();
//        } else {
//            code = optionalCode.get();
//        }
//
//        if (code != 200) {
//            return new WeatherNowResponse();
//        }
//
//        Optional<WeatherNowResponse> optionalWeatherNowResponse = response.map(HttpEntity::getBody);
//        if (!optionalWeatherNowResponse.isPresent()) {
//            return new WeatherNowResponse();
//        } else {
//            weatherHourly = optionalWeatherNowResponse.get();
//        }
//
//        return weatherHourly;
//    }
//}
